﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Apps.IService;
using Apps.Model.Models;
using Apps.Model.ViewModels;
using Apps.Repository;
using Apps.Repository.UnitOfWork;
using AutoMapper;

namespace Apps.Service
{
    public class SysUserService : BaseService<SysUser, int>, ISysUserService
    {
        private readonly IUnitOfWork _unitOfWork;
        private readonly IMapper _mapper;
        public SysUserService(IUnitOfWork unitOfWork, IMapper mapper) : base(unitOfWork, mapper)
        {
            _unitOfWork = unitOfWork;
            _mapper = mapper;
        }

        public async Task<SysUser> GetUserByNameAsync(string username)
        {
            var userRepo = _unitOfWork.GetRepository<SysUser, int>();
            var data = await userRepo.GetAsync(s => s.UserName == username);
            var user = data.FirstOrDefault();
            return user;
        }

        public async Task<UserDto> GetUserDtoByNameAsync(string username)
        {
            var user = await GetUserByNameAsync(username);
            return MapTo<UserDto>(user);  // 使用基类映射方法
        }

    }
}
